package nl.hszuyd.stack;

/**
 * 
 * @author miriam
 *
 */
public class Stack {

	private Object[] objects = new Object[255];
	private int size;
	
	public void push(Object obj) {
		
		if (obj == null) {
			throw new NullPointerException("Argument obj is null");
		}
		
		objects[size] = obj;
		size++;
	}
	
	public Object pop() {
		
		if (size == 0) {
			throw new IllegalStateException("Cannot push an empty stack"); 
		}
		
		size--;
		
		Object object = objects[size];
		objects[size] = null;
		
		return object;
	}
	
	public boolean isEmpty() {
		return size==0;
	}
	
	public int size() {
		return size;
	}
	
	public void clear() {
		
		for (int i = 0; i < size; i++) {
			objects[i] = null;
		}
		
		size = 0;
		
	}
}
